﻿using SqlSugar;

namespace DataAcquisitionDAL
{
    /// <summary>
    /// 
    ///</summary>
    [SugarTable("d_device")]
    public class DeviceModel
    {
        /// <summary>
        /// 备  注:ID
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
        public UInt32 ID { get; set; }

        /// <summary>
        /// 备  注:设备编号
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "number", IsPrimaryKey = true)]
        public UInt32 Number { get; set; }

        /// <summary>
        /// 备  注:设备名称
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "name")]
        public string Name { get; set; } = null!;

        /// <summary>
        /// 备  注:地址
        /// 默认值:1
        ///</summary>
        [SugarColumn(ColumnName = "slave_address")]
        public String SlaveAddress { get; set; } = null!;

        /// <summary>
        /// 备  注:波特率
        /// 默认值:9600
        ///</summary>
        [SugarColumn(ColumnName = "baudrate")]
        public UInt32 Baudrate { get; set; }

        /// <summary>
        /// 备  注:串口地址
        /// 默认值:COM1
        ///</summary>
        [SugarColumn(ColumnName = "port_address")]
        public string PortAddress { get; set; } = null!;

        /// <summary>
        /// 根据设备名判断是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool RecordExistenceWithName(string name)
        {
            Dictionary<string, Object> where = new Dictionary<string, Object>();
            where["name"] = name;
            List<DeviceModel> list = SqlSugarHelper.Inquireable<DeviceModel>(where);
            if (list.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 根据设备编号判断是否存在
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public static bool RecordExistenceWithNumber(uint number)
        {
            Dictionary<string, Object> where = new Dictionary<string, Object>();
            where["number"] = number;
            List<DeviceModel> list = SqlSugarHelper.Inquireable<DeviceModel>(where);
            if (list.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
